package emulator.util;

import java.util.LinkedList;
import java.util.List;

import emulator.hardware.clock.Clock;
import emulator.hardware.clock.ClockHandle;

public class TickThread extends Thread
{
	private List<TickWorker> workerList = new LinkedList<TickWorker>();
	private ClockHandle clock;

	public TickThread(Clock clock)
	{
		if (clock != null)
			this.clock = clock.acquireHandle();
	}
	
	public void addTickWorker(TickWorker tickWorker)
	{
		workerList.add(tickWorker);
		tickWorker.setClock(clock);
	}

	@Override
	public void run() 
	{
		for (;;)
		{
			clock.tick();
			for (TickWorker tickWorker : workerList)
				tickWorker.runTick();
		}
	}
}
